import Quill from 'quill';

const Inline = Quill.import('blots/inline');

class TagBlot extends Inline {
  static blotName = 'tag';
  static tagName = 'span';
  static className = 'tag-container';

  static create(value): any {
    const node = super.create(value);
    node.setAttribute('contenteditable', 'false');
    node.setAttribute('style', `background:${value.background};color:${value.color};`);

    node.addEventListener('click', (event) => {
      console.log('click~~');
    });
    return node;
  }

  static value(domNode): any {
    console.log('static value()', domNode);
  }

  static formats(domNode: Node): void {
    console.log('static formats()');
  }

  value(): any {
    console.log('value()');
  }

  format(format, value): void {
    console.log('format() format, value', format, value);
  }

  formats(): any {
    console.log('formats()');
    return super.formats();
  }

  // 仅限叶子blots

  // Returns the value represented by domNode if it is this Blot's type
  // No checking that domNode can represent this Blot type is required so
  // applications needing it should check externally before calling.
  // 如果domNode是此Blot的类型，则返回由domNode表示的值。不需要检查domNode是否可以表示此Blot类型，因此需要它的应用程序应该在调用之前从外部进行检查。
  // static value(domNode): any;

  // Return value represented by this blot
  // Should not change without interaction from API or
  // user change detectable by update()
  // 在没有API交互或通过update()检测到用户更改的情况下，此blot表示的返回值不应更改
  // value(): any;

  // Formattable blots only
  // 仅限可格式化的blot

  // Returns format values represented by domNode if it is this Blot's type
  // No checking that domNode is this Blot's type is required.
  // 如果domNode是此Blot的类型，则返回由domNode表示的格式值。不需要检查domNode是否为此Blot的类型。
  // static formats(domNode: Node);

  // Apply format to blot. Should not pass onto child or other blot.
  // 将格式应用于blot。不应传染给孩子或其他blot。
  // format(format: name, value: any);

  // Return formats represented by blot, including from Attributors.
  // 由blot表示的返回格式，包括来自属性的返回格式。
  // formats(): Object;
}

export default TagBlot;
